package com.i2863.receipt.util;

/**
 * Created by Administrator on 2017/11/23.
 */

import com.alibaba.fastjson.JSONObject;
import lombok.Data;

/**
 * 返回json数据通用类
 */
@Data
public class ResultJson {

    //0 ： 成功，1 ： 失败
    private Integer code;
    //返回的信息
    private String message;
    //需要返回的内容
    private Object content;

    /**
     * 返回成功消息
     * @return
     */
    public static String successResult(String message,Object content){
        ResultJson result = new ResultJson();
        result.code = 0;
        result.message = message;
        result.content = content;
        return JSONObject.toJSONString(result);
    }

    /**
     * 成功，自定义code返回
     * @param code
     * @param message
     * @param content
     * @return
     */
    public static String successResult(Integer code,String message,Object content){
        ResultJson result = new ResultJson();
        result.code = code;
        result.message = message;
        result.content = content;
        return JSONObject.toJSONString(result);
    }

    /**
     *返回成功消息（）
     * @return
     */
    public static String successMeg(String message){
        ResultJson result = new ResultJson();
        result.code = 0;
        result.message = message;
        return JSONObject.toJSONString(result);
    }

    /**
     *返回成功消息（自定义状态码）
     * @return
     */
    public static String successMeg(Integer code,String message){
        ResultJson result = new ResultJson();
        result.code = code;
        result.message = message;
        return JSONObject.toJSONString(result);
    }

    /**
     * 返回错误消息
     * @param message
     * @return
     */
    public static String errorMes(String message){
        ResultJson result = new ResultJson();
        result.code = 1;
        result.message = message;
        return JSONObject.toJSONString(result);
    }

    /**
     * 返回错误消息(自定义状态码)
     * @param message
     * @return
     */
    public static String errorMes(Integer code,String message){
        ResultJson result = new ResultJson();
        result.code = code;
        result.message = message;
        return JSONObject.toJSONString(result);
    }


    /**
     * 返回失败消息,自定义返回码
     * @param message
     * @return
     */
    public static String errorResult(Integer code,String message){
        ResultJson result = new ResultJson();
        result.code = code;
        result.message = message;
        return JSONObject.toJSONString(result);
    }

}
